//
//  GXDPPayViewController.m
//  YaDiuDiu
//
//  Created by 欧洪飞 on 2017/8/24.
//  Copyright © 2017年 jy. All rights reserved.
//

#import "GXDPPayViewController.h"

#import "GXPayView.h"
#import "GXPayTwoView.h"
#import "GXPayThreeView.h"
#import "GXPayCell.h"
#import "SelectPayCell.h"
#import "SHDZViewController.h"
#import "YuePayViewController.h"
#import "PaySuccessViewController.h"
#import "UITextView+JKInputLimit.h"
#import "UIButton+JKTouchAreaInsets.h"
#import "WXApi.h"

#import "Order.h"
#import "APAuthV2Info.h"
#import "RSADataSigner.h"
#import <AlipaySDK/AlipaySDK.h>
@interface GXDPPayViewController ()<UITableViewDelegate,UITableViewDataSource,SHDZViewControllerDelegate,UITextViewDelegate,YuePayViewControllerDelegate>{
    NSArray *arrImgs;
    NSArray *arrTits;
    SelectPayCell *payCell;
    NSString *str;//订单号
    GXPayView *payView;//
    UILabel *labMethod;//支付方式
    GXPayTwoView *dpView;
    GXPayThreeView *threeView;
    CGFloat        _totalMoney;//jiage
    NSDictionary   *_nowDic;
    CGFloat        _money;//
}

@property (nonatomic,strong)UITableView *tableView;
//主要是用来接收用户上一次所选的cell的indexpath
@property (nonatomic,strong) NSIndexPath *lastPath;

@property (nonatomic,copy)NSString *payState;//支付方式

@property (nonatomic,copy)NSString *state;//地址区别

@property (nonatomic,strong)NSDictionary *dic;

@property (nonatomic,copy)NSString *payMent;//支付方式




@end

@implementation GXDPPayViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = COLOR_RGB(242, 242, 242, 1);
    
    [self showNav:@"订单"];
    arrImgs = @[@"微信2",@"支付宝-(1)",@"钱包-(1)"];
    arrTits = @[@"微信支付",@"支付宝支付",@"余额支付"];
    [self loadUI];
    
    [self loadData];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(clicks) name:@"PayResultNSNotification" object:nil];
    NSLog(@"array:%@",self.array);
    
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self loadNum];//生成订单号
    
}
//支付成功方法
- (void)clicks{
    NSLog(@"aaaa");
    //下单
    [self loadPay];
}

- (void)loadUI{
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, ScreenWidth, ScreenHeight-64-50) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.view addSubview:_tableView];
    
    UIView *footView = [[UIView alloc] initWithFrame:CGRectMake(0, ScreenHeight-50, ScreenWidth, 50)];
    footView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:footView];
    
    UIButton *btnPay = [UIButton buttonWithType:UIButtonTypeCustom];
    btnPay.frame = CGRectMake(ScreenWidth/3*2, 0, ScreenWidth/3, 50.0);
    btnPay.backgroundColor = [UIColor redColor];
    [btnPay setTitle:@"去支付" forState:UIControlStateNormal];
    [btnPay setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btnPay addTarget:self action:@selector(clickPay) forControlEvents:UIControlEventTouchUpInside];
    [footView addSubview:btnPay];
    
    UILabel *labPrice = [[UILabel alloc] init];
    NSString *price = [user objectForKey:@"SumPrice"];
    NSString *sendPrice = [user objectForKey:@"sendPrice"];
    CGFloat _pri = [price floatValue] + [sendPrice floatValue];
    labPrice.tag = 4444;
    labPrice.text = [NSString stringWithFormat:@"￥%.2f",_pri];
    labPrice.textColor = [UIColor redColor];
    labPrice.font = [UIFont boldSystemFontOfSize:18.0];
    [footView addSubview:labPrice];
    [labPrice makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(footView.left).offset(16);
        make.top.equalTo(footView.top).offset(8);
    }];
    
    labMethod = [[UILabel alloc] init];
    labMethod.text = @"微信支付";
    labMethod.hidden = YES;
    labMethod.textColor = [UIColor darkGrayColor];
    labMethod.font = [UIFont systemFontOfSize:12.0];
    [footView addSubview:labMethod];
    [labMethod makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(footView.left).offset(16);
        make.bottom.equalTo(footView.bottom).offset(-8);
    }];
    
    payView = [[[NSBundle mainBundle] loadNibNamed:@"GXPayView" owner:nil options:nil] lastObject];
    payView.frame = CGRectMake(0, 0, ScreenWidth, 130);
    _tableView.tableHeaderView = payView;
    //隐藏
    payView.labName.hidden = YES;
    
    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(click1)];
    payView.view1.userInteractionEnabled = YES;
    [payView.view1 addGestureRecognizer:tap1];
    
    //备注
    dpView = [[[NSBundle mainBundle] loadNibNamed:@"GXPayTwoView" owner:nil options:nil] lastObject];
    dpView.frame = CGRectMake(0, 0, ScreenWidth, 150);
    _tableView.tableFooterView = dpView;
    
    dpView.textView.delegate = self;
    dpView.textView.text = @"请填写对商家的备注";
    dpView.textView.jk_maxLength = 30;
    dpView.textView.textColor = [UIColor grayColor];
    
}

#pragma mark - UITextViewDelegate
-(void)textViewDidBeginEditing:(UITextView *)textView{
    
    if ([textView.text isEqualToString:@"请填写对商家的备注"]) {
        textView.text = @"";
        textView.textColor = [UIColor blackColor];
    }
}

-(void)textViewDidEndEditing:(UITextView *)textView{
    if (textView.text.length < 1) {
        textView.text = @"请填写对商家的备注";
        textView.textColor = [UIColor grayColor];
    }
}

- (void)click1{
    SHDZViewController *shdz = [[SHDZViewController alloc] init];
    shdz.delegate = self;
    [self.navigationController pushViewController:shdz animated:YES];
}
#pragma -mark SHDZViewControllerDelegate
-(void)sendText:(NSDictionary *)text{
    payView.labName.hidden = NO;
    _dic = text;
    //NSString *place = [NSString stringWithFormat:@"%@%@%@%@",[_dic objectForKey:@"province"],[_dic objectForKey:@"city"],[_dic objectForKey:@"area"],[_dic objectForKey:@"detailedadd"]];
    NSString *name = [NSString stringWithFormat:@"%@ %@",[text objectForKey:@"consignee"],[text objectForKey:@"userphone"]];
    payView.labPlace.text = [_dic objectForKey:@"detailedadd"];
    payView.labName.text = name;
    NSLog(@"%@",text);
    _money = 0.00;
    NSMutableDictionary *parmas = [NSMutableDictionary dictionary];
    [parmas setObject:[NSString stringWithFormat:@"%f",_locationCoorder.longitude] forKey:@"start_longitude"];
    [parmas setObject:[NSString stringWithFormat:@"%f",_locationCoorder.latitude] forKey:@"start_latitude"];
    [parmas setObject:text[@"longitude"] forKey:@"end_longitude"];
    [parmas setObject:text[@"latitude"] forKey:@"end_latitude"];
    NSLog(@"parmas:%@",parmas);
    NSString *url = [NSString stringWithFormat:@"%@/App/Banner/km",urlHead];
    [[AFHTTPSessionManager manager] POST:url parameters:parmas success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"res:%@",responseObject);
        NSLog(@"%f",ceilf([responseObject[@"result"][@"km"] floatValue] ) );
        _totalMoney = ceilf([responseObject[@"result"][@"km"] floatValue] );
        [_tableView reloadData];
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"error:%@",error);
    }];

    
    
}




-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}
#pragma -mark UITableViewDataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return self.array.count;
    }
    return arrImgs.count;
}
- (void)tapButtonPressed:(UIButton *)sender{
    [self showAlert];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        static NSString *cellId = @"Cell0";
        GXPayCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
        if (!cell) {
            cell = [[[NSBundle mainBundle] loadNibNamed:@"GXPayCell" owner:nil options:nil] lastObject];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        _nowDic = self.array[indexPath.row];
        cell.labName.text = [_nowDic objectForKey:@"productname"];
        NSString *count = [NSString stringWithFormat:@"%li",[[_nowDic objectForKey:@"quantity"] integerValue]];
        cell.labNum.text = [NSString stringWithFormat:@"x%li",[count integerValue]];
        cell.labMoney.text = [_nowDic objectForKey:@"unitprice"];//
        _money += [count integerValue] * [[_nowDic objectForKey:@"unitprice"] floatValue];
        NSString *quantity = [NSString stringWithFormat:@"%.2f",[_totalMoney <= 2 ? @"6" : [NSString stringWithFormat:@"%.2f", 6 + 2 * (_totalMoney - 2)] floatValue] + [[_nowDic objectForKey:@"quantity"] integerValue] * [[_nowDic objectForKey:@"quantity"] integerValue]];
        NSString *pri = [_nowDic objectForKey:@"unitprice"];
        CGFloat a = [quantity floatValue] * [pri floatValue];
        if (indexPath.row<self.array.count) {
            CGFloat c = a+a;
            NSLog(@"c:%f",c);
        }
        
        return cell;
    }else{
        static NSString *cellId = @"Cell1";
        payCell = [tableView dequeueReusableCellWithIdentifier:cellId];
        if (!payCell) {
            payCell = [[[NSBundle mainBundle] loadNibNamed:@"SelectPayCell" owner:nil options:nil] lastObject];
        }
        payCell.selectionStyle = UITableViewCellSelectionStyleNone;
        payCell.images.image = [UIImage imageNamed:arrImgs[indexPath.row]];
        payCell.labTit.text = arrTits[indexPath.row];
        
        NSInteger row = indexPath.row;
        NSInteger oldRow = _lastPath.row;
        if (row == oldRow && _lastPath != nil) {
            payCell.imageSel.image = [UIImage imageNamed:@"勾"];
        }else{
            payCell.imageSel.image = [UIImage imageNamed:@"椭圆-2-拷贝"];
        }
        
        return payCell;
    }
    
}

- (void)showAlert{
    //起始配送距离
//    NSString *startkm = [_dic objectForKey:@"startkm"];
//    NSString *cost = [_dic objectForKey:@"cost"];
//    NSString *minxcost = [_dic objectForKey:@"minxcost"];
//    NSString *km = [_dic objectForKey:@"km"];
//    NSString *title = [NSString s]
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"2公里范围为6元\n超出2公里每公里多收2元" preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *action = [UIAlertAction actionWithTitle:@"知道了" style:UIAlertActionStyleCancel handler:nil];
    [alert addAction:action];
    
    [self presentViewController:alert animated:YES completion:nil];
}
//行高
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        return 44.0;
    }else{
        return 50.0;
    }
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        
    }else{
        NSInteger newrow = indexPath.row;
        NSInteger oldRow = (self.lastPath != nil)?self.lastPath.row:-1;
        if (newrow != oldRow) {
            payCell = [tableView cellForRowAtIndexPath:indexPath];
            payCell.imageSel.image = [UIImage imageNamed:@"勾"];
            
            payCell = [tableView cellForRowAtIndexPath:self.lastPath];
            payCell.imageSel.image = [UIImage imageNamed:@"椭圆-2-拷贝"];
            self.lastPath = indexPath;
            
        }
        _payState = arrTits[indexPath.row];
        labMethod.text = _payState;
        labMethod.hidden = NO;
    }
}

//头视图
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    if (section == 0) {
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 40.0)];
        view.backgroundColor = [UIColor whiteColor];
        
        UILabel *lab = [[UILabel alloc] init];
        lab.text = _orderName;
        lab.font = [UIFont systemFontOfSize:15.0];
        [view addSubview:lab];
        [lab makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(view.centerX);
            make.centerY.equalTo(view.centerY);
        }];
        
        return view;
    }else{
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 40.0)];
        view.backgroundColor = COLOR_RGB(242, 242, 242, 1);
        
        UILabel *labLine = [[UILabel alloc] initWithFrame:CGRectMake(16, 10, 4, 20)];
        labLine.backgroundColor = [UIColor blueColor];
        [view addSubview:labLine];
        
        UILabel *lab = [[UILabel alloc] initWithFrame:CGRectMake(28, 10, 150, 20)];
        lab.text = @"选择支付方式";
        lab.font = [UIFont systemFontOfSize:15.0];
        lab.font = [UIFont systemFontOfSize:15.0];
        [view addSubview:lab];
        
        return view;
    }
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 40.0;
}
//尾视图
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    
    if (section == 0) {
        threeView = [[[NSBundle mainBundle] loadNibNamed:@"GXPayThreeView" owner:nil options:nil] lastObject];
        threeView.frame = CGRectMake(0, 0, ScreenWidth, 100);
        NSString *price     =  _totalMoney <= 2 ? @"6" : [NSString stringWithFormat:@"%.2f", 6 + 2 * (_totalMoney - 2)];// [user objectForKey:@"SumPrice"];
        NSString *sendPrice =  [NSString stringWithFormat:@"￥%.2f",_money + [price floatValue] ];
        UILabel *labPrice =  (  UILabel *)[self.view viewWithTag:4444];
        labPrice.text  =  [NSString stringWithFormat:@"￥%.2f",_money + [price floatValue] ];
        threeView.labSum.text =  sendPrice; //[NSString stringWithFormat:@"￥%.2f",_money + [price floatValue] ];
        threeView.tapButton.jk_touchAreaInsets = UIEdgeInsetsMake(20, 20, 20, 20);
        threeView.labPSF.text = price;// [NSString stringWithFormat:@"%.2f",[sendPrice floatValue]];
        [threeView.tapButton addTarget:self
                                action:@selector(tapButtonPressed:)
                      forControlEvents:UIControlEventTouchUpInside];
        return threeView;
    }else{
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 40.0)];
        view.backgroundColor = COLOR_RGB(242, 242, 242, 1);
        
        
        return view;
    }
    
}
//尾视图高度
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (section == 0) {
        return 100.0;
    }
    return 0.0;
}
//支付功能
- (void)clickPay{
    [self loadNum];//生成订单号
    if (_payState.length == 0) {
        
        [LICGToast showWithText:@"请选择支付方式"];
        return;
    }else if (![_dic objectForKey:@"area"]){
        
        [LICGToast showWithText:@"请选择取件地址"];
        return;
    }
    
    if ([_payState isEqualToString:@"微信支付"]) {
        _payMent = @"2";
//        [self loadPay];
        [self loadWX];
        
    }else if ([_payState isEqualToString:@"支付宝支付"]){
        _payMent = @"3";
        [self loadAliPay];
    }else if ([_payState isEqualToString:@"银联支付"]){
        
    }else{//余额支付
        _payMent = @"5";
        YuePayViewController *pay = [[YuePayViewController alloc] init];
        pay.delegate = self;
        pay.price = _price;
        [self presentViewController:pay animated:YES completion:nil];
    }
    
}
#pragma -mark YuePayViewControllerDelegate
-(void)sendState:(NSString *)state{
    [self loadPay];
}
//干洗下单
- (void)loadPay{
    NSData *data = [NSJSONSerialization dataWithJSONObject:self.array options:nil error:nil];
    NSString *stra = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    NSLog(@"str:%@",stra);
    
    NSMutableDictionary *parmas = [NSMutableDictionary dictionary];
    [parmas setObject:[user objectForKey:@"userid"] forKey:@"userid"];
    [parmas setObject:str forKey:@"ordernumber"];
    [parmas setObject:@"8" forKey:@"ridemoneyone"];
    [parmas setObject:@"1" forKey:@"ordermoney"];
    [parmas setObject:_mid forKey:@"merchantid"];
    
    [parmas setObject:_orderName forKey:@"ordername"];
    [parmas setObject:_payMent forKey:@"ordertype"];
    [parmas setObject:@"0" forKey:@"balance"];
    [parmas setObject:[_dic objectForKey:@"detailedadd"] forKey:@"address"];
    [parmas setObject:[_dic objectForKey:@"consignee"] forKey:@"consignee"];
    
    [parmas setObject:[_dic objectForKey:@"userphone"] forKey:@"phone"];
    [parmas setObject:@"2" forKey:@"stroke"];//距离
    if (dpView.textView.text.length > 0) {
        [parmas setObject:dpView.textView.text forKey:@"remark"];//备注
    }
    [parmas setObject:[_dic objectForKey:@"longitude"] forKey:@"takelongitude"];
    [parmas setObject:[_dic objectForKey:@"latitude"] forKey:@"takelatitude"];
    [parmas setObject:stra forKey:@"product"];//产品
    NSLog(@"parmas:%@",parmas);
    NSString *url = [NSString stringWithFormat:@"%@/App/Blitzcrank/cleaningorderpay",urlHead];
    [[AFHTTPSessionManager manager] POST:url parameters:parmas success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"res:%@",responseObject);
        NSString *error = [NSString stringWithFormat:@"%li",[[responseObject objectForKey:@"error"] integerValue]];
        if ([error integerValue] == 200) {
            PaySuccessViewController *pay = [[PaySuccessViewController alloc] init];
            pay.asd = _price;
            [self.navigationController pushViewController:pay animated:YES];
        }
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"error:%@",error);
    }];
    
}
//微信支付
- (void)loadWX{
    NSMutableDictionary *parmas = [NSMutableDictionary dictionary];
    [parmas setObject:@"0.01" forKey:@"total"];
    [parmas setObject:str forKey:@"ordernumber"];
    [parmas setObject:@"干洗" forKey:@"subject"];
    [parmas setObject:@"干洗描述" forKey:@"detail"];
    [parmas setObject:@"http://ydd.xtangguo.com/index.php/App/Blitzcrank/cleaningorderpay" forKey:@"notify_url"];
    NSString *url = [NSString stringWithFormat:@"%@/App/WxPay/dopay",urlHead];
    
    [[AFHTTPSessionManager manager] POST:url parameters:parmas success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"res:%@",responseObject);
        NSDictionary *dic = responseObject;
        [LICGToast showWithText:@"支付成功"];
        [self loadWXpay:dic];
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"error:%@",error);
    }];
}

- (void)loadWXpay:(NSDictionary *)dic{
    //需要创建这个支付对象
    PayReq *req   = [[PayReq alloc] init];
    
    //由用户微信号和AppID组成的唯一标识，用于校验微信用户
    req.openID = [dic objectForKey:@"appid"];
    
    // 商家id，在注册的时候给的
    req.partnerId = [dic objectForKey:@"partnerid"];
    
    // 预支付订单这个是后台跟微信服务器交互后，微信服务器传给你们服务器的，你们服务器再传给你
    req.prepayId  = [dic objectForKey:@"prepayid"];
    
    // 根据财付通文档填写的数据和签名
    //这个比较特殊，是固定的，只能是即req.package = Sign=WXPay
    req.package   = [dic objectForKey:@"package"];
    
    // 随机编码，为了防止重复的，在后台生成
    req.nonceStr  = [dic objectForKey:@"noncestr"];
    
    // 这个是时间戳，也是在后台生成的，为了验证支付的
    NSString * stamp = [dic objectForKey:@"timestamp"];
    req.timeStamp = stamp.intValue;
    
    // 这个签名也是后台做的
    req.sign = [dic objectForKey:@"sign"];
    
    //发送请求到微信，等待微信返回onResp
    [WXApi sendReq:req];
    
}

//调用支付
- (void)loadAliPay{
    //2017041006619216
    NSString *appID = @"2017041006619216";//持有者ID
    //支付宝公钥
    NSString *rsa2PrivateKey = @"";//支付宝公钥 2048
    
    NSString *rsaPrivateKey = @"MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAIeaW3BL5JgblDIBDCec3JAfiWs88agOcQzUOXlVHncFAtFyJjsJLV2+DV32ASog2Wk5Dh+KcbefEg/dtHx/y8Tgt++zfm6eTo/KHwgka+SiGQNs8nvldeYwXu1nQ3xDhGfGBJL7F0PXBkALoJNQE6xVM5n/KeSzZfESYcPARXRlAgMBAAECgYAsrI7JXUdvUU6udqfheQ01Mh6cxNQ8cJ2QA2736TIDNhRqmje8JVbb1lwjA4P4tB/MSa68d2jlfLN/pKPsjFG+CxcFeSnpvnVBy27m4Eg7CAQ+8M+1bKluWu6hNXUSw5oLFEWOdTX5hOlU2XjHRo9t4H+LWUZPwN64qbrp68EuVQJBAN+TAg8zgVDE8yZZ+KuCCGHHq9vpiKw9207gJv+TSlnEstB2CgyZH/9w36ytk5g7u+85msmuGUaV+rg5m28G4NsCQQCbRRnXeU/UE5klSPy/jhXHCAUpQbGjoqWPbDSi+Ahb3211gftUJdJsQfFq2JK28iY0kHYfciGJ7VA7sJ8XPWO/AkBY+uYv7JzD646mLdq1T6xMVi6E+J4HhxrYeoeq4hEORyWvp7r6JptAi8jJrc93IBb879019U9j8170oSDGgGNPAkBn0qba6+UzG/+1bL6En890DKrW0XSkxGcMJgB0UIHWXOnmPwn9VGUFunphRXulFPny//3cPQasIaEaqJlYgtYlAkEAxwPw51+P2Wjcq0bc6377mWlMUtiQpORY/ABBsu8bbon/kweveCr4V952MAWNLHQqSPZrtBVO1y1RND64+8UwTA==";//1024
    //partner和seller获取失败,提示
    if ([appID length] == 0 ||
        ([rsa2PrivateKey length] == 0 && [rsaPrivateKey length] == 0))
    {
        NSLog(@"appid/ras不能为空");
        return;
    }
    
    /*
     *生成订单信息及签名
     */
    //将商品信息赋予AlixPayOrder的成员变量
    Order* order = [Order new];
    
    // NOTE: app_id设置
    order.app_id = appID;
    
    // NOTE: 支付接口名称
    
    order.method = @"alipay.trade.app.pay";
    //order.method = [NSString stringWithFormat:@"%@/house/payorder/pay/togetherNotify.html",urlHead];
    
    // NOTE: 参数编码格式
    order.charset = @"utf-8";
    
    // NOTE: 当前时间点
    NSDateFormatter* formatter = [NSDateFormatter new];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    order.timestamp = [formatter stringFromDate:[NSDate date]];
    ////ALI40247
    // NOTE: 支付版本
    order.version = @"1.0";
    
    // NOTE: sign_type 根据商户设置的私钥来决定
    order.sign_type = (rsa2PrivateKey.length > 1)?@"RSA2":@"RSA";
    
    // NOTE: 商品数据
    order.biz_content = [BizContent new];
    order.biz_content.body = @"我是测试数据";
    order.biz_content.subject = _orderName;
    order.biz_content.out_trade_no = str;
//    order.biz_content.out_trade_no = [self generateTradeNO]; //订单ID（由商家自行制定）
    //ALI38173
    order.biz_content.timeout_express = @"30m"; //超时时间设置
    order.biz_content.total_amount = [NSString stringWithFormat:@"%.2f", 0.01]; //商品价格
    
    
    //将商品信息拼接成字符串
    NSString *orderInfo = [order orderInfoEncoded:NO];
    NSString *orderInfoEncoded = [order orderInfoEncoded:YES];
    
    // NOTE: 获取私钥并将商户信息签名，外部商户的加签过程请务必放在服务端，防止公私钥数据泄露；
    //       需要遵循RSA签名规范，并将签名字符串base64编码和UrlEncode
    NSString *signedString = nil;
    
    RSADataSigner* signer = [[RSADataSigner alloc] initWithPrivateKey:((rsa2PrivateKey.length > 1)?rsa2PrivateKey:rsaPrivateKey)];
    
    if ((rsa2PrivateKey.length > 1)) {
        signedString = [signer signString:orderInfo withRSA2:YES];
    } else {
        signedString = [signer signString:orderInfo withRSA2:NO];
    }
    
    // NOTE: 如果加签成功，则继续执行支付
    if (signedString != nil) {
        //应用注册scheme,在AliSDKDemo-Info.plist定义URL types
        NSString *appScheme = @"alisdkdemo";
        
        // NOTE: 将签名成功字符串格式化为订单字符串,请严格按照该格式
        
        NSString *orderString = [NSString stringWithFormat:@"%@&sign=%@",
                                 orderInfoEncoded, signedString];
        
        //订单信息
        //        orderString = @"测试";
        // NOTE: 调用支付结果开始支付
        [[AlipaySDK defaultService] payOrder:orderString
                                  fromScheme:appScheme callback:^(NSDictionary *
                                                                  resultDic) {
                                      
                                      if ([[resultDic objectForKey:@"resultStatus"] integerValue] == 9000) {
                                          NSLog(@"支付成功");
                                          [LICGToast showWithText:@"支付成功"];
                                      }else{
                                          NSLog(@"支付失败");
                                          [LICGToast showWithText:@"支付失败"];
                                      }
                                      NSLog(@"reslut ============= %@",resultDic);
                                      NSLog(@"memo:%@",[resultDic objectForKey:@"memo"]);
                                  }];
    }
    
}
//随机生产订单号
- (NSString *)generateTradeNO
{
    static int kNumber = 15;
    
    NSString *sourceStr = @"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    NSMutableString *resultStr = [[NSMutableString alloc] init];
    srand((unsigned)time(0));
    for (int i = 0; i < kNumber; i++)
    {
        unsigned index = rand() % [sourceStr length];
        NSString *oneStr = [sourceStr substringWithRange:NSMakeRange(index, 1)];
        [resultStr appendString:oneStr];
    }
    return resultStr;
}

//配送费
- (void)loadData{
    NSString *url = [NSString stringWithFormat:@"%@/App/Blitzcrank/shippingfee",urlHead];
    [[AFHTTPSessionManager manager] POST:url parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"配送费res:%@",responseObject);
        _dic = [responseObject objectForKey:@"result"];
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"error:%@",error);
    }];
}

//生成订单号
- (void)loadNum{
    NSString *url = [NSString stringWithFormat:@"%@/App/Shoppingcart/ordernumber",urlHead];
    [[AFHTTPSessionManager manager] POST:url parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"res:%@",responseObject);
        str = [responseObject objectForKey:@"result"];
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"error:%@",error);
    }];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
